package com.erp.util;

import java.util.HashMap;

public class AjaxResult extends HashMap<String, Object> {

    private Integer code;
    private String msg;

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    private AjaxResult() {

    }

    public static AjaxResult success() {
        AjaxResult ajaxResult = new AjaxResult();

        ajaxResult.code = 5200;
        ajaxResult.msg = "执行成功";

        ajaxResult.put("code", 5200);
        ajaxResult.put("message", "执行成功");
        return ajaxResult;
    }

    public static AjaxResult error() {
        AjaxResult ajaxResult = new AjaxResult();

        ajaxResult.code = 5500;
        ajaxResult.msg = "执行错误";

        ajaxResult.put("code", 5500);
        ajaxResult.put("message", "执行错误");
        return ajaxResult;
    }

    public static AjaxResult error(int code, String message) {
        AjaxResult ajaxResult = new AjaxResult();

        ajaxResult.code = code;
        ajaxResult.msg = message;

        ajaxResult.put("code", code);
        ajaxResult.put("message", message);
        return ajaxResult;

    }

    public AjaxResult add(String key, Object value) {
        this.put(key, value);
        return this;
    }
}

